package com.gzp.queue;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

/**
 * 队列的生产者
 * 
 * @author Administrator
 *
 */
public class TestQueueProducer {

	@SuppressWarnings("resource")
	public static void main(String[] args) {
		ApplicationContext context = new ClassPathXmlApplicationContext("classpath:application-queue.xml");
		JmsTemplate jmsTemplate = context.getBean(JmsTemplate.class);
		jmsTemplate.send(new MessageCreator() {

			@Override
			public Message createMessage(Session session) throws JMSException {
				TextMessage textMessage = session.createTextMessage("mq-spring-queue");
				return textMessage;
			}
		});// 发送到默认目的地
//		jmsTemplate.send(destinationName, messageCreator);// 发送到默认目的地，并设置名称
//		jmsTemplate.send(destination, messageCreator);// 发送到自定义目的地
		System.out.println("消息发送完成！");
	}
}
